﻿using System;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Interfacing.Mathematica {
    public class MmaEvaluateNode : ContextFuncNode {

        public MmaEvaluateNode() :
            base() {
            base.Value = "mmaEvaluate";
        }

        public override object Evaluate() {
            if (Parameters.Count < 1) {
                throw new ArgumentException(
                    "usage: mmaEvaluate(expr);");
            }

            Node root = Parameters[0];
            MathematicaExpressionTranslator translator 
                = new MathematicaExpressionTranslator("");
            string ex = translator.Translate(root);
            object result = MathematicaKernel.Instance.Evaluate(ex);

            return result;
        }
    }
}
